//=============================================================================
// M79 Grenade launcher Inventory class
//=============================================================================
class M79FGrenadeLauncher extends KFWeapon;

var     float               ForceZoomOutTime;
var		Pawn				WeapOwner;

//=============================================================================
// Functions
//=============================================================================

function AttachToPawn(Pawn P)
{
	WeapOwner = P;
	Super.AttachToPawn(P);
}

function float GetAIRating()
{
	local AIController B;

	B = AIController(Instigator.Controller);
	if ( (B == None) || (B.Enemy == None) )
		return AIRating;

	return (AIRating + 0.0003 * FClamp(1500 - VSize(B.Enemy.Location - Instigator.Location),0,1000));
}

function byte BestMode()
{
	return 0;
}

function bool RecommendRangedAttack()
{
	return true;
}

//TODO: LONG ranged?
function bool RecommendLongRangedAttack()
{
	return true;
}

function float SuggestAttackStyle()
{
	return -1.0;
}

simulated function WeaponTick(float dt)
{
    super.WeaponTick(dt);

    if( bAimingRifle && ForceZoomOutTime > 0 && Level.TimeSeconds - ForceZoomOutTime > 0 )
    {
	    ForceZoomOutTime = 0;

    	ZoomOut(false);

    	if( Role < ROLE_Authority)
			ServerZoomOut(false);
	}
}

// Force the weapon out of iron sights shortly after firing so the textured
// scope gets the same disadvantage as the 3d scope
simulated function bool StartFire(int Mode)
{
    if( super.StartFire(Mode) )
    {
        ForceZoomOutTime = Level.TimeSeconds + 0.4;
        return true;
    }

    return false;
}

function GiveTo(Pawn Other, optional Pickup Pickup)
{
	Ammo[0].AmmoAmount = 0;
	Ammo[1].AmmoAmount = 0;
	Super.GiveTo(Other, Pickup);
}

function DropFrom(vector StartLocation)
{
	local int m;
	local Pickup Pickup;
	local vector Direction;

	if (!bCanThrow)
		return;

	ClientWeaponThrown();

	for (m = 0; m < NUM_FIRE_MODES; m++)
	{
		if (FireMode[m].bIsFiring)
			StopFire(m);
	}

	if ( Instigator != None )
	{
		DetachFromPawn(Instigator);
		Direction = vector(Instigator.Rotation);
	}
	else if ( Owner != none )
	{
		Direction = vector(Owner.Rotation);
	}

	Pickup = Spawn(PickupClass,,, StartLocation);
	if ( Pickup != None )
	{
		WeaponPickup(Pickup).AmmoAmount[0] = 0;
		WeaponPickup(Pickup).AmmoAmount[1] = 0;
		Pickup.InitDroppedPickupFor(self);
		Pickup.Velocity = Velocity + (Direction * 100);
		if (Instigator.Health > 0)
			WeaponPickup(Pickup).bThrown = true;
	}

	Destroyed();

	Destroy();
}

defaultproperties
{
	 bHasSecondaryAmmo=true
     MagCapacity=1
     ReloadRate=0.010000
     HudImage=Texture'KillingFloor2HUD.WeaponSelect.M79_unselected'
     SelectedHudImage=Texture'KillingFloor2HUD.WeaponSelect.M79'
     Weight=4.000000
     bHasAimingMode=True
     IdleAimAnim="Idle_Iron"
     StandardDisplayFOV=65.000000
     TraderInfoTexture=Texture'KillingFloor2HUD.Trader_Weapon_Icons.Trader_M79'
     PlayerIronSightFOV=70.000000
     ZoomedDisplayFOV=45.000000
     FireModeClass(0)=Class'M79FFire'
     FireModeClass(1)=Class'M79FAltFire'
     PutDownAnim="PutDown"
     SelectSound=Sound'KF_M79Snd.M79_Select'
     SelectForce="SwitchToAssaultRifle"
     AIRating=0.650000
     CurrentRating=0.650000
     Description="A classic Vietnam era grenade launcher. Launches single high explosive grenades."
     DisplayFOV=65.000000
     Priority=200
     InventoryGroup=3
     GroupOffset=5
     PickupClass=Class'M79FPickup'
     PlayerViewOffset=(X=18.000000,Y=20.000000,Z=-6.000000)
     BobDamping=6.000000
     AttachmentClass=Class'M79FAttachment'
     IconCoords=(X1=253,Y1=146,X2=333,Y2=181)
     ItemName="M79 Flame Launcher"
     LightType=LT_None
     LightBrightness=0.000000
     LightRadius=0.000000
     Mesh=SkeletalMesh'KF_Weapons2_Trip.M79_Trip'
     Skins(0)=Combiner'KF_Weapons2_Trip_T.Special.M79_cmb'
}
